//
//  MyTrajectorySegViewController.m
//  BaseProject
//
//  Created by 王洋 on 2020/9/2.
//  Copyright © 2020 王洋. All rights reserved.
//
#import "XLPageViewController.h"
#import "MyTrajectoryViewController.h"

#import "MyTrajectorySegViewController.h"

@interface MyTrajectorySegViewController ()<XLPageViewControllerDelegate,XLPageViewControllerDataSrouce>

@property (nonatomic, strong) XLPageViewController *pageViewController;


@end

@implementation MyTrajectorySegViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self initView];
}

- (void)initView {

    self.title = @"足迹";
    self.view.backgroundColor = UIColorHex(0xffffff);
    
    [self initPageViewController];
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightBtn setTitleColor:UIColorHex(0x333333) forState:UIControlStateNormal];
    [rightBtn setTitle:@"清空" forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(clearAction) forControlEvents:UIControlEventTouchUpInside];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    rightBtn.frame = CGRectMake(0,0,40,30);
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItems =@[rightItem];
    
}

- (void)clearAction {
    [self request_clear];
}

- (void)goBack {
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)initPageViewController {
    
    XLPageViewControllerConfig *config = [XLPageViewControllerConfig defaultConfig];
    config.shadowLineColor = UIColorHex(0xff4242);
    config.titleSelectedFont = [UIFont boldSystemFontOfSize:16];
    config.titleNormalFont = [UIFont systemFontOfSize:16];
    config.titleViewAlignment = XLPageTitleViewAlignmentCenter;
    config.showTitleInNavigationBar = false;
    config.titleViewStyle = XLPageTitleViewStyleBasic;
    config.titleWidth = (TTScreenWidth-60)/3;
    config.separatorLineHidden = true;
    config.shadowLineAnimationType = XLPageShadowLineAnimationTypeZoom;
    config.shadowLineWidth = 20;
    
    self.pageViewController = [[XLPageViewController alloc] initWithConfig:config];

    self.pageViewController.delegate = self;
    self.pageViewController.dataSource = self;
    [self addChildViewController:self.pageViewController];
    [self.view addSubview:self.pageViewController.view];
    
    [self.pageViewController.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
//        make.height.mas_equalTo(NavBar_Height);
    }];
}

#pragma mark -
#pragma mark TableViewDelegate&DataSource
- (UIViewController *)pageViewController:(XLPageViewController *)pageViewController viewControllerForIndex:(NSInteger)index {

    MyTrajectoryViewController *vc = [[MyTrajectoryViewController alloc] initWith:index];
    return vc;
}

- (NSString *)pageViewController:(XLPageViewController *)pageViewController titleForIndex:(NSInteger)index {
    return [self titles][index];
}

- (NSInteger)pageViewControllerNumberOfPage {
    return [self titles].count;
}

- (void)pageViewController:(XLPageViewController *)pageViewController didSelectedAtIndex:(NSInteger)index {
    NSLog(@"切换到了：%@",[self titles][index]);
}

#pragma mark -
#pragma mark 标题数据
- (NSArray *)titles {
    return @[@"套餐",@"婚品",@"案例"];
}

//
- (void)request_clear {

    NSMutableDictionary *dic = @{}.mutableCopy;
    
    NSString *url = [NSString stringWithFormat:@"%@%@",TT_Global_Api_Domain,API_ClearFootPrint];

    [dic setValue:[TTUserModel sharedObject].userId forKey:@"userId"];
    
    [SVProgressHUD showWithStatus:@"正在清空足迹"];
    WEAKSELF
    [TTHttpManager postRequestWithUrl:url TimeOut:10 PostData:dic FinishBlock:^(id  _Nonnull data) {
        
        [SVProgressHUD dismiss];
        
        if ([data isKindOfClass:[NSDictionary class]]) {
            //请求成功
            NSInteger code = [[data valueForKey:@"code"] integerValue];
            if (code == 10000) {

                [weakSelf.navigationController popViewControllerAnimated:YES];
            }
        }
    } FailedBlock:^(NSError * _Nonnull error) {
        [SVProgressHUD dismiss];
    }];
    
}




@end
